package com.order.itemcategoryproject.controller;

import com.order.itemcategoryproject.pojo.TreeNode;
import com.order.itemcategoryproject.pojo.dArcStaff;
import com.order.itemcategoryproject.pojo.vClassTree;
import com.order.itemcategoryproject.pojo.vClassTreeLan;
import com.order.itemcategoryproject.service.dArcStaffService;
import com.order.itemcategoryproject.service.vClassTreeLanSerrvice;
import com.order.itemcategoryproject.service.vClassTreeService;
import com.order.itemcategoryproject.utils.AjaxResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static com.order.itemcategoryproject.utils.ParseUrl.getUrl;
import static com.order.itemcategoryproject.utils.parseItemData.buildHierarchy;

@RestController
@RequestMapping("/menu")
public class vClassTreeController {

    @Autowired
    private vClassTreeService vClassTreeService;
    @Autowired
    private vClassTreeLanSerrvice vClassTreeLanSerrvice;
    @Autowired
    private dArcStaffService dArcStaffService;


    @GetMapping("/getMenuList/{currentLanguage}")
    public TreeNode getAllCategory(@PathVariable String currentLanguage, HttpServletRequest request) {
        String queryString = request.getQueryString();
        String staffID = getUrl(queryString, "StaffID");
        // 首先判断参数是否都存在
        dArcStaff staffInfo = dArcStaffService.getStaffInfoByStaId(staffID);
//        List<vClassTree> vClassTrees = vClassTreeService.selectAllCategory();
        // 根据客户编号获取客户信息
        List<vClassTreeLan> vClassTrees = vClassTreeLanSerrvice.getAllCategorys(currentLanguage, staffInfo.getCus_segmentation());
        return buildHierarchy(vClassTrees, null, staffInfo);
    }

    /**
     * 获取所有小类名称列表
     * @return
     */
    @GetMapping("/getSmClassList")
    public AjaxResult getAllSmClassList() {
        return AjaxResult.success(vClassTreeService.selectSmallClassInfo());
    }
}
